// pages/prize/prize.js
const app = getApp()
var t = require('./../../utils/request.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    ticketData: null,
    ticketData2: null,
    show: false
  },

  toQDetail: function (event) {
    wx.navigateTo({
      url: '/pages/detail/detail?qid=' + event.currentTarget.dataset.id,
    })
    console.log('/pages/detail/detail?qid=' + event.currentTarget.dataset.id)
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.paystatus, 8888)
    if (options.paystatus == 1) {
      this.setData({
        show: true
      })
    }

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    t.toPost('/minip/ticket/list', {
      uid: wx.getStorageSync('userInfo').id
    }, (res) => {
      console.log(res, 1000)
      this.setData({
        ticketData: res.data
      })
    })

    t.toPost('/minip/ticket/list', {
      uid: wx.getStorageSync('userInfo').id,
      type: 1
    }, (res) => {
      this.setData({
        ticketData2: res.data
      })
    })
  },

  

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
    * 用户点击右上角分享
  */
  onShareAppMessage: function () {
    return {
      title: '不用剪线头的杰克A5，邀您9.9元抢500体验券！',
      path: '/pages/index/index',
      imageUrl: 'http://qny.zhiniugroup.com/blog/20190106162150.png',
      success: function (res) {
        console.log(res, '分享成功')
      }
    }
  },

  toChou: function () {
    if (wx.getStorageSync('userInfo')) {
      t.toPost('/minip/user/info', {
        uid: wx.getStorageSync('userInfo').id
      }, (res) => {
        console.log(res)
        if (res.code == '000000') {
          if (res.data.is_ticket == 0) {
            wx.navigateTo({
              url: '/pages/chou2/index',
            })
          } else {
            wx.navigateTo({
              url: '/pages/chou1/index',
            })
          }
        }
      })
    } else {
      wx.navigateTo({
        url: '/pages/index/index',
      })
    }
  },

  onClose: function () {
    this.setData({
      show: false
    })
  }

})